package UniCli.SinaWeibo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import weibo4j.Status;
import weibo4j.User;
import weibo4j.Weibo;
import weibo4j.WeiboException;
import zzw.unicliinterfaces.GetTimeLinesInterface;
import zzw.unicliinterfaces.LoggedInUser;
import zzw.unicliinterfaces.UniCliStatus;
import zzw.unicliinterfaces.UniCliUser;

public class GetTimeLinesSinaWeibo implements GetTimeLinesInterface {

	@Override
	public List<UniCliStatus> GetTimeLines(LoggedInUser user, int type) {
		// TODO Auto-generated method stub
		List<UniCliStatus> result = null;
		List<Status> statuses=null;
		if(!user.blogSite.equalsIgnoreCase("sinaweibo")){
			System.out.println("不是sinaweibo的getTimeLine接口 ");
			return null;
		}
		try {
			//Weibo weibo = new Weibo("zzw719196@126.com", "931318");
			Weibo weibo = new Weibo(user.userID, user.password);
			switch(type)
			{
			case 1:
				statuses = weibo.getPublicTimeline();
				break;
			case 2:
				statuses = weibo.getFriendsTimeline();
				break;
			case 3:
				statuses = weibo.getUserTimeline();
				break;
			}			
		} catch (WeiboException te) {
			System.out.println("Failed to get timeline: " + te.getMessage());
			//System.exit(-1);
			return null;
		}
		if(statuses.size() < 1){
			return null;
		}
		result = new ArrayList<UniCliStatus>(statuses.size());
		for (Status status : statuses) {
            //System.out.println(status.getUser().getName() + ":" +
            //                   status.getText());
            //System.out.println(status);
            UniCliStatus s = new UniCliStatus();
//            private Date createdAt;
//            private long id;
//            private String text;
//            private String source;
//            private boolean isTruncated;
//            private long inReplyToStatusId;
//            private int inReplyToUserId;
//            private boolean isFavorited;
//            private String inReplyToScreenName;
//            private double latitude = -1;
//            private double longitude = -1;
//            private String thumbnail_pic;
//            private String bmiddle_pic;
//            private String original_pic;
//            private UniCliRetweetDetails retweetDetails;
//            private static final long serialVersionUID = 1608000492860584608L;
//            private UniCliUser user = null;
            
            
            
            
//            
            s.setCreatedAt(status.getCreatedAt());
            s.setId(status.getId());
            s.setText(status.getText());
            s.setSource(status.getSource());
            s.setTruncated(status.isTruncated());
            s.setInReplyToStatusId(status.getInReplyToStatusId());
            s.setInReplyToUserId(status.getInReplyToUserId());
            s.setFavorited(status.isFavorited());
            s.setInReplyToScreenName(status.getInReplyToScreenName());
            s.setLatitude(status.getLatitude());
            s.setLongitude(status.getLongitude());
            s.setThumbnail_pic(status.getThumbnail_pic());
            s.setBmiddle_pic(status.getBmiddle_pic());
            s.setOriginal_pic(status.getOriginal_pic());
            s.setRetweetDetails(null); //这个参数目前先定为null，以后再改
            //s.setUser(null);//同上 20101104
            //设置UniCliUser的值
            User u = status.getUser(); 
            UniCliUser uu=new UniCliUser();
//            private int id;
//            private String name;
//            private String screenName;
//            private String location;
//            private String description;
//            private String profileImageUrl;
//            private String url;
//            private boolean isProtected;
//            private int followersCount;
//
            uu.setId(u.getId());
            uu.setName(u.getName());
            uu.setScreenName(u.getScreenName());
            uu.setLocation(u.getLocation());
            uu.setDescription(u.getDescription());
            uu.setProfileImageUrl(u.getProfileImageURL().toString());
            //uu.setUrl(u.getURL().toString()); //空指针错误，有空再调
            uu.setProtected(u.isProtected());
            uu.setFollowersCount(u.getFollowersCount());
            
//            private Date statusCreatedAt;
//            private long statusId = -1;
//            private String statusText = null;
//            private String statusSource = null;
//            private boolean statusTruncated = false;
//            private long statusInReplyToStatusId = -1;
//            private int statusInReplyToUserId = -1;
//            private boolean statusFavorited = false;
//            private String statusInReplyToScreenName = null;
//
            uu.setStatusCreatedAt(u.getStatusCreatedAt());
            uu.setStatusId(u.getStatusId());
            uu.setStatusText(u.getStatusText());
            uu.setStatusSource(u.getStatusSource());
            uu.setStatusTruncated(u.isStatusTruncated());
            uu.setStatusInReplyToStatusId(u.getStatusInReplyToStatusId());
            uu.setStatusInReplyToStatusId(u.getStatusInReplyToUserId());
            uu.setStatusFavorited(u.isStatusFavorited());
            uu.setStatusInReplyToScreenName(u.getStatusInReplyToScreenName());
//            private String profileBackgroundColor;
//            private String profileTextColor;
//            private String profileLinkColor;
//            private String profileSidebarFillColor;
//            private String profileSidebarBorderColor;
//            private int friendsCount;
//            private Date createdAt;
//            private int favouritesCount;
//            private int utcOffset;
//            private String timeZone;
//            private String profileBackgroundImageUrl;
//            private String profileBackgroundTile;
//            private boolean following;
//            private boolean notificationEnabled;
//            private int statusesCount;
//            private boolean geoEnabled;
//            private boolean verified;
            uu.setProfileBackgroundColor(u.getProfileBackgroundColor());
            uu.setProfileTextColor(u.getProfileTextColor());
            uu.setProfileLinkColor(u.getProfileLinkColor());
            uu.setProfileSidebarFillColor(u.getProfileSidebarFillColor());
            uu.setProfileSidebarBorderColor(u.getProfileSidebarBorderColor());
            uu.setFriendsCount(u.getFriendsCount());
            uu.setCreatedAt(u.getCreatedAt());
            uu.setFavouritesCount(u.getFavouritesCount());
            uu.setUtcOffset(u.getUtcOffset());
            uu.setTimeZone(u.getTimeZone());
            uu.setProfileBackgroundImageUrl(u.getProfileBackgroundImageUrl());
            uu.setProfileBackgroundTile(u.getProfileBackgroundTile());
            uu.setFollowing(u.isFollowing());
            uu.setNotificationEnabled(u.isNotificationEnabled());
            uu.setStatusesCount(u.getStatusesCount());
            uu.setGeoEnabled(u.isGeoEnabled());
            uu.setVerified(u.isVerified());
            s.setUser(uu);
            result.add(s);
        }
//		for(UniCliStatus s:result){
//			System.out.println(s);
//		}
		return result;
	}

}
